package com.job.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.job.common.ResponseResult;
import com.job.common.enums.ResultCodeEnum;
import com.job.common.exception.ParameterIsNullException;
import com.job.common.exception.UserException;
import com.job.controller.req.ChatRecordsVO;
import com.job.controller.req.ReadMessageVO;
import com.job.controller.resp.UnreadRespVO;
import com.job.pojo.Message;
import com.job.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;

@RestController
@Api("私信接口")
@RequestMapping("/message")
public class MessageController {

    @Resource
    private MessageService messageService;

    @GetMapping("/queryUnreadList")
    @ApiOperation("未读消息列表")
    public ResponseResult<ArrayList<UnreadRespVO>> QueryUnreadList(Integer userId)
            throws UserException, ParameterIsNullException {
        return messageService.QueryUnreadList(userId);
    }

    @PostMapping("/read")
    @ApiOperation("读消息")
    public ResponseResult<ResultCodeEnum> Read(@Valid @RequestBody ReadMessageVO messageVO)
            throws ParameterIsNullException {
        return messageService.read(messageVO);
    }

    @ApiOperation("查看聊天记录")
    @PostMapping ("/chatRecords")
    public ResponseResult<Page<Message>> messageRecords(@Valid @RequestBody ChatRecordsVO chatRecordsVO){
        return  messageService.queryChatRecords(chatRecordsVO);
    }
}
